package com.tjetc.view.teacherview;

import com.github.pagehelper.PageInfo;
import com.tjetc.proxy.CilentProxy;
import com.tjetc.view.teacherview.MyCourseView_In_Content;
import com.zhiyun.domain.Course;
import com.zhiyun.domain.CourseComment;
import com.zhiyun.domain.Student;
import com.zhiyun.service.CourseCommentService;
import com.zhiyun.service.CourseService;
import com.zhiyun.service.StudentService;
import com.zhiyun.vo.Result;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Scanner;

public class MyCourseView_In {
    StudentService studentService=CilentProxy.getProxyInstance(StudentService.class);
    CourseService courseService=CilentProxy.getProxyInstance(CourseService.class);
    CourseCommentService courseCommentService= CilentProxy.getProxyInstance(CourseCommentService.class);
    Scanner scanner=new Scanner(System.in);
    public void start(Course course1){
        while (true){
            System.out.println("~~~~~~~欢迎进入课程~~~~~~");
            System.out.println("1.查看课程内容");
            System.out.println("2.课程详细信息");
            System.out.println("3.签到");
            System.out.println("4.抢答");
            System.out.println("5.通知");
            System.out.println("6.评价");
            System.out.println("7.考试");
            System.out.println("8.课程学生信息");
            System.out.println("0.返回上一级");
            int i = scanner.nextInt();
            switch (i){
                case 1:
                    new MyCourseView_In_Content().start(course1);
                    break;
                case 2:
                    allInfo(course1);
                    break;
                case 3:
                   new MyCourse_Check().start(course1);
                    break;
                case 4:
                    new MyCourseView_In_Answer().start(course1);
                    break;
                case 5:
                    new MyCourseView_In_Notice().start(course1);
                    break;
                case 6:
                    pingjia(course1);
                    break;
                case 7:
                    new MyCourseView_In_Exams().start(course1);
                    break;
                case 8:
                    allStudent(course1);
                    break;
                case 0:

                    return;
                default:
                    System.out.println("输入有误,请重新输入");
            }
        }
    }

    private void allStudent(Course course1) {
        while (true){
            Result result = courseService.AllStudent(course1.getId());
            if (result.getCode()==200){
                List<Student> obj = (List<Student>) result.getObj();
                for (Student student : obj) {
                    System.out.println("学生id"+student.getId()+"      学生姓名:"+student.getTruename());
                }
            }else {
                System.out.println("获取失败");
            }
            break;
        }
    }

    private void allInfo(Course course1) {
        System.out.println(course1);
    }
    private void pingjia(Course course) {
        int a=1;
        boolean boo1=true;
        while (true){
            boolean boo=true;
            System.out.println(a+"************");
            Result courseCommentByIdAndPage = courseCommentService.findCourseCommentByIdAndPage(course.getId(), a);
            if (courseCommentByIdAndPage.getCode()==200){
                PageInfo<CourseComment> obj = (PageInfo<CourseComment>) courseCommentByIdAndPage.getObj();
                while (boo){
                    List<CourseComment> list = obj.getList();
                    for (CourseComment courseComment : list) {
                        Result result = studentService.myInfo(courseComment.getStudentId());
                        if (result.getCode()==200){
                            Student obj1 = (Student) result.getObj();
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


                            if (obj1!=null){
                                // 将Date转换为String

                                System.out.println("id:"+courseComment.getId()+"     评价:"+courseComment.getComment()+"  评价学生:"+obj1.getTruename());
                            }
                        }}
                    System.out.println(obj.getPageNum()+"/"+obj.getPages());
                    System.out.println("请输入 上一页:0  下一页:1 退出:-1 ");
                    int i = scanner.nextInt();
                    switch (i){
                        case 0:
                            int prePage = obj.getPrePage();
                            System.out.println(prePage);
                            a=prePage;
                            boo=false;
                            break;
                        case 1:
                            int nextPage = obj.getNextPage();
                            System.out.println(nextPage);
                            a=nextPage;
                            boo=false;
                            break;
                        case -1:
                            return;
                    }
                }
            }

        }
    }
}
